package com.cd.order.dto;

import com.cd.order.jpa.domain.CameraOrder;
import com.cd.schedule.jpa.domain.ScheduleEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;

/**
 * CameraOrder 数据传输对象（DTO）
 * 用于向前端返回订单及其关联日程信息，避免暴露持久层实体
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CameraOrderDto implements Serializable {

    private static final long serialVersionUID = 1L;

    // ========== 订单基本信息 ==========
    private Long orderId;
    private String name;
    private String place;
    private String time;              // 拍摄时间 YYYY-MM-DD 格式字符串
    private Date createTime;
    private String customerName;
    private String customerRemark;
    private String type;              // 场照/外景/棚拍/其他
    private String clothType;         // cos/汉服/lo/jk/日常
    private String cosName;           // 扮演角色（仅cos）
    private String cosIp;             // 角色对应IP
    private Integer num;              // 数量
    private Double realPrice;         // 实收金额
    private Double allPrice;          // 应付金额
    private String remark;            // 金额备注：互勉单、预约单等
    private Boolean isShow;           // 是否允许客户授权展示
    private String status;            // 订单状态

    // ========== 关联日程信息 ==========
    private Long linkSchedule;        // 关联的日程ID（ScheduleEntity.id）
    private String linkPic;

    /**
     * 嵌套的 ScheduleEntity 简化版 DTO
     * 避免直接传整个 Entity，只传需要的字段
     */
    private ScheduleEntity schedule;

    /**
     * 内部静态类：Schedule 简化 DTO
     * 只包含前端常用字段，如日期、时间段、标题
     */
//    @Data
//    @NoArgsConstructor
//    @AllArgsConstructor
//    public static class Schedule {
//        private Long id;
//        private Date date;             // 日程日期
//        private String startHour;      // 开始时间，如 "09:00"
//        private String endHour;        // 结束时间，如 "12:00"
//        private String title;          // 日程标题
//        private String remark;         // 日程备注（可选）
//    }

    // ========================================================
    // 工具方法：将 CameraOrder + ScheduleEntity 封装成 DTO
    // ========================================================

    /**
     * 静态工厂方法：从 DTO 构建CameraOrder
     *
     * @param cameraOrderDto  订单实体
     * @return CameraOrder
     */
    public static CameraOrder buildCameraOrder(CameraOrderDto cameraOrderDto) {
        CameraOrder cameraOrder = new CameraOrder(
                cameraOrderDto.getOrderId(),
                cameraOrderDto.getName(),
                cameraOrderDto.getPlace(),
                cameraOrderDto.getTime(),
                cameraOrderDto.getCreateTime(),
                cameraOrderDto.getCustomerName(),
                cameraOrderDto.getCustomerRemark(),
                cameraOrderDto.getType(),
                cameraOrderDto.getClothType(),
                cameraOrderDto.getCosName(),
                cameraOrderDto.getCosIp(),
                cameraOrderDto.getNum(),
                cameraOrderDto.getRealPrice(),
                cameraOrderDto.getAllPrice(),
                cameraOrderDto.getRemark(),
                cameraOrderDto.getIsShow(),
                cameraOrderDto.getStatus(),
                cameraOrderDto.getLinkSchedule(),
                cameraOrderDto.getLinkPic()
        );
        return cameraOrder;
    }
}